<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="favicon.ico" >
	<link rel="Shortcut Icon" href="favicon.ico" />
	<!--[if lt IE 9]>
	<script type="text/javascript" src="lib/html5.js"></script>
	<script type="text/javascript" src="lib/respond.min.js"></script>
	<![endif]-->
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin.pro/css/h-ui.admin.pro.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.9/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/business/css/style.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script><![endif]-->
	<!--/meta 作为公共模版分离出去-->

	<title>新增图片</title>
	<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
</head>
<body>
	<article class="Hui-admin-page-container">
		<form class="form form-horizontal" id="form-article-add">
			<!-- 添加一个隐藏的输入框，从后台获取到宿舍信息后，将宿舍id传入其中，方便取用 -->
			<div><input type="text" id="dorId" name="dorId" hidden></div>

			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>位置：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" autocomplete="off" value="" id="position" name="position" readonly>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>宿舍名称：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" autocomplete="off" id="apartmentName" name="apartmentName" readonly>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>宿舍楼层：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" id="floor" name="floor" readonly>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>门牌号：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" name="doorNum" id="doorNum" readonly>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>申报标题：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="请输入您要申报的标题信息" id="title" name="title">
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2">图片：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<span class="btn-upload">
						<a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
						<input type="file" multiple name="btnUploadFileThumb" id="image" class="input-file">
					</span>
				</div>
			</div>
			<div class="row clearfix">
				<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>描述：</label>
				<div class="form-controls col-xs-8 col-sm-9">
					<textarea name="desc" id="desc" cols="" rows="" class="textarea textarea-picture"  placeholder="请输入维修详情。。。最少10个字符"></textarea>
				</div>
			</div>

			<div class="row clearfix">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
					<button class="btn btn-primary radius" type="button" id="maintainAddBtn"><i class="Hui-iconfont">&#xe632;</i> 报修</button>
					<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
		</form>
	</article>

	<!--_footer 作为公共模版分离出去-->
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/3.1.1/layer.js"></script>
	<script type="text/javascript" src="static/h-ui/js/H-ui.js"></script>
	<script type="text/javascript" src="static/h-ui.admin.pro/js/h-ui.admin.pro.js"></script>
	<!--/_footer /作为公共模版分离出去-->

	
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
	<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
	<script type="text/javascript" src="static/business/js/main.js"></script>
	<script type="text/javascript">
	function layer_close(){
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}
		$(function(){
			getMenu();

			// 1. 宿舍信息显示
			$.ajax({
				method:"post",
				url:"dormitory?action=getDormitoryInfo",
				type:"json",
				success:function (result){
					console.log(result);
					if (result.code == 50001){
						var info = result.data;
						$("#position").val(info.position);
						$("#apartmentName").val(info.apartmentName);
						$("#floor").val(info.floor);
						$("#doorNum").val(info.doorNum);
						$("#dorId").val(info.dorId);
					}else{
						alert(result.msg);
						location.href="/login.html";
					}
				}
			});

			// 2. 点击报修按钮事件
			$("#maintainAddBtn").click(function () {
				// 检查标题和描述是否为空
			    var title =	$("#title").val();
			    var desc = $("#desc").val();
			    if(title.length<=0){
			    	alert("请输入标题");
			    	return;
				}
			    if(desc.length <= 10){
			    	alert("描述信息不少于10个字");
			    	return;
				}
			    var dorId = $("#dorId").val();
				console.log(dorId + '  '+ title + '  ' + desc)

			    //console.log(images);
			    // 获取文件信息
				//var images = $("#image")[0].files[0];
				var formData = new FormData();
				formData.append("dorId", dorId);
				formData.append("title", title);
				formData.append("desc",desc);

				// 遍历选择的文件，存入数组传给后端（多文件上传）
				var images = new Array();
				var length = $("#image")[0].files.length;
				for(var i=0; i < length ;i++){
					var image = $("#image")[0].files[i];
					console.log(image);
					formData.append("images", image);
				}
				//formData.append("images", images[0]);

				// 提交信息给后台
				$.ajax({
					method:"post",
					url:"maintainDormitory?action=addMaintainDormitory",
					data:formData,
					cache:false,
					processData:false,
					contentType:false,
					success:function (result){
						console.log(result);
						alert(result.msg);
						location.href="/index.html";
					}
				});
			})


			$(".textarea-picture").Huitextarealength({
				minlength: 10,
				maxlength: 500
			});
		});
	</script>
</body>
</html>
